package com.mysite.seckill.web.config;

import com.mysite.seckill.web.util.DateUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import java.util.Date;

@Configuration
public class CommonConfig {

    @Bean
    public Converter<String, Date> convertDateTime() {
        return new Converter<String, Date>() {
            @Override
            public Date convert(String source) {
                if (source == null || source.length() == 0) {
                    return null;
                }
                return DateUtil.parse(source);
            }
        };
    }
}
